def concise_function(state_var, function_code):
    """
    检查函数代码中是否有对state_var的赋值操作，
    并返回包含这些赋值的代码片段（智能扩展切片范围，最多100行）。
    
    参数:
        state_var: 要检查的变量名（如'ssl->options.serverState'）
        function_code: 函数的源代码字符串
        
    返回:
        生成器，每次生成一个包含赋值操作的代码片段
    """
    lines = function_code.split('\n')
    var_parts = state_var.replace('->', '.').split('.')
    var_name = var_parts[-1]  # 提取变量名最后部分
    
    # 找到所有赋值操作的行号
    assignment_lines = []
    for i, line in enumerate(lines):
        stripped = line.strip()
        # 跳过注释行
        if stripped.startswith('#') or stripped.startswith('//'):
            continue
            
        # 检查简单赋值
        if '=' in line and any(
            part in line.split('=')[0] 
            for part in var_parts
        ):
            assignment_lines.append(i)
        
        # 检查复合赋值
        for op in ['+=', '-=']:
            if op in line and any(
                part in line.split(op)[0] 
                for part in var_parts
            ):
                assignment_lines.append(i)
                break
    
    # 合并相邻的赋值区域
    merged_ranges = []
    if assignment_lines:
        current_start = assignment_lines[0]
        current_end = assignment_lines[0]
        
        for line in assignment_lines[1:]:
            if line <= current_end + 50:  # 如果下一个赋值在50行内，扩展范围
                current_end = line
            else:
                merged_ranges.append((current_start, current_end))
                current_start = current_end = line
        merged_ranges.append((current_start, current_end))
    
    # 生成代码片段
    for start, end in merged_ranges:
        # 计算扩展范围，确保不超过100行
        context_size = min(25, 100 // (end - start + 1)) if start != end else 25
        expanded_start = max(0, start - context_size)
        expanded_end = min(len(lines), end + context_size + 1)
        
        # 确保总行数不超过100
        while expanded_end - expanded_start > 100:
            if expanded_end - start > end - expanded_start:
                expanded_end -= 1
            else:
                expanded_start += 1
        
        yield '\n'.join(lines[expanded_start:expanded_end])

# 示例用法
if __name__ == "__main__":
    # 示例函数代码
    sample_code = """
def example_function(ssl):
    # 初始化部分
    config = load_config()
    ssl->options.serverState = 0  # 初始化状态
    
    # 处理循环
    for i in range(10):
        if check_condition():
            ssl->options.serverState = 1
            prepare_resources()
            # 中间有50行其他代码...
            validate_input()
            
            # 另一个赋值
            ssl->options.serverState = 2
            finalize_operation()
    
    # 清理部分
    ssl->options.serverState = -1
    cleanup()
    return result
    """
    
    # 使用生成器获取所有相关代码片段
    for i, snippet in enumerate(concise_function("ssl->options.serverState", sample_code)):
        print(f"\n代码片段 {i+1}:")
        print("="*50)
        print(snippet)
        print("="*50)